/* Copyright (c) 2006, Jan Flora <janflora@diku.dk>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 *  - Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *  - Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  - Neither the name of the University of Copenhagen nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
  @author Jan Flora <janflora@diku.dk>
*/

module MlmeAssociateIndicationResponseM
{
	provides
	{
		interface MlmeAssociateIndicationResponse;
	}
	uses
	{
		interface MemoryManager as BufferMng;
	}
}
implementation
{		
	async command void MlmeAssociateIndicationResponse.getDeviceAddress( Mlme_AssociateIndicationResponse indication,
	                                                                     uint8_t *deviceAddr )
	{
		nwkAssociateInd_t* msg = &((MlmeIndicationResponse_t*)indication)->msg.indication.msgData.associateInd;
		NTOUHCPY64(msg->deviceAddress, deviceAddr);
	}
	
	async command uint8_t MlmeAssociateIndicationResponse.getCapabilityInformation( Mlme_AssociateIndicationResponse indication )
	{
		nwkAssociateInd_t* msg = &((MlmeIndicationResponse_t*)indication)->msg.indication.msgData.associateInd;
		return msg->capabilityInfo;
	}
	
	async command bool MlmeAssociateIndicationResponse.getSecurityUse( Mlme_AssociateIndicationResponse indication )
	{
		nwkAssociateInd_t* msg = &((MlmeIndicationResponse_t*)indication)->msg.indication.msgData.associateInd;
		return msg->securityUse;
	}
	
	async command uint8_t MlmeAssociateIndicationResponse.getAclEntry( Mlme_AssociateIndicationResponse indication )
	{
		nwkAssociateInd_t* msg = &((MlmeIndicationResponse_t*)indication)->msg.indication.msgData.associateInd;
		return msg->AclEntry;
	}

	async command void MlmeAssociateIndicationResponse.setDeviceAddress( Mlme_AssociateIndicationResponse response,
	                                                                     uint8_t *deviceAddress )
	{
		mlmeAssociateRes_t* msg = &((MlmeIndicationResponse_t*)response)->msg.response.msgData.associateRes;
		NTOUHCPY64(deviceAddress, msg->deviceAddress);
		if (!(response->msg.response.msgType)) {
			// Security false by default.
			msg->securityEnable = FALSE;
		}
	}
	
	async command result_t MlmeAssociateIndicationResponse.setAssocShortAddress( Mlme_AssociateIndicationResponse response,
	                                                                             uint16_t assocShortAddress )
	{
		mlmeAssociateRes_t* msg = &((MlmeIndicationResponse_t*)response)->msg.response.msgData.associateRes;
		NTOUHCPY16((uint8_t*)&assocShortAddress, msg->assocShortAddress);
		return SUCCESS;
	}
	
	async command result_t MlmeAssociateIndicationResponse.setStatus( Mlme_AssociateIndicationResponse response,
	                                                                  Ieee_Status status )
	{
		mlmeAssociateRes_t* msg = &((MlmeIndicationResponse_t*)response)->msg.response.msgData.associateRes;
		msg->status = status;
		return SUCCESS;
	}
	
	async command result_t MlmeAssociateIndicationResponse.setSecurityEnable( Mlme_AssociateIndicationResponse response )
	{
		mlmeAssociateRes_t* msg = &((MlmeIndicationResponse_t*)response)->msg.response.msgData.associateRes;
		response->msg.response.msgType = TRUE;
		msg->securityEnable = TRUE;
		return SUCCESS;
	}
}
